package com.ccnf.web.component;

import com.ccnf.core.utils.SystemClock;
import com.ccnf.model.mapper.InvitationRecordMapper;
import com.ccnf.service.RewardService;
import com.ccnf.service.ScheduleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class ScheduledTasks {
    @Autowired
    private InvitationRecordMapper invitationRecordMapper;
    @Autowired
    private RewardService rewardService;
    @Autowired
    private ScheduleService scheduleService;

    @Scheduled(cron = "0 10 0 1/1 * ?")// 零点执行
    public void handleInZeroTime() {
        long startTime = SystemClock.milli();
        long second = SystemClock.zeroSecond();
        long beforeSecond = second - 86400;// 当前时间的前一天时间戳
        boolean isContinue = scheduleService.beforeScheduleTask(beforeSecond);
        if (isContinue) {
            invitationRecordMapper.emptyToday();
            rewardService.handleRewardRecord(beforeSecond);
            scheduleService.afterScheduleTask(beforeSecond, startTime);
        }
    }

//    @Scheduled(cron = "0 0 0 ? * MON ")// 每周一执行
//    @Scheduled(cron = "0 0 0 ? * 2 ")// 每周一执行
//    public void reportInWeekTime() {
//        long currentTime = SystemClock.second();// 当前时间戳（秒）
//        long mondayTime = currentTime - 604800;// 当前前一周的周一的零点时间戳（秒）
//        handleEveryday(mondayTime, currentTime);
//    }
}